package com.baohua.dao.impl;

import java.util.List;


import org.springframework.stereotype.Repository;

import com.baohua.dao.BaseDao;
import com.baohua.dao.InventoryDao;
import com.baohua.model.Inventory;
import com.baohua.model.Staff;
/**
 * 查询库存的实现类
 * @author czp
 *
 */

@Repository("inventoryDao")
public class InventoryDaoImpl extends BaseDao implements InventoryDao{

	
	/**
	 * 根据querySQL查询相应的数据
	 * @param querySQL 查询语句
	 * @param page
	 * @param pagesize
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Inventory> getInventory(String querySQL, int page, int pagesize){
		return this.getSession().createQuery(querySQL).setFirstResult(page).setMaxResults(pagesize).list();
	}
	
	/**
	 * 根据物料编码进行查询
	 * @param inventoryNo
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Inventory  getInventoryByInventoryNo(String inventoryNo){
		Inventory i = (Inventory)this.getSession().createQuery("from Inventory i where i.inventoryNO = ?").setString(0, inventoryNo)
		.uniqueResult();
		return i;
	}
	
	/**
	 * 增加物料信息
	 * @param inventory
	 */
	@Override
	public void addInventory(Inventory inventory) {
		this.getSession().save(inventory);
		
	}

	/**
	 * 修改物料信息
	 * @param inventory
	 */
	@Override
	public void updateInventory(Inventory inventory) {
		this.getSession().update(inventory);
		
	}

	/**
	 * 删除物料信息
	 * @param inventory
	 */
	@Override
	public void deleteInventory(Inventory inventory) {
		this.getSession().delete(inventory);
		
	}

	/**
	 * 根据语句统计数据
	 * @param hql HQL语句
	 * @return
	 */
	@Override
	public long countInventory(String hql) {
		long count = (Long)this.getSession().createQuery(hql).uniqueResult();
		return count;
	}

	/**
	 * 根据ID进行查询
	 * @param inventoryId
	 * @return
	 */
	@Override
	public Inventory getInventoryByInventoryId(int inventoryId) {
		Inventory i = (Inventory)this.getHibernateTemplate().load(Inventory.class, inventoryId);
		return i;
	}

	/**
	 * 根据物料编码的数组, 查询库存信息
	 * @param inventoryNOs
	 * @return
	 */
	@Override
	public List<Inventory> queryByInventoryNOs(String[] inventoryNOs) {
		String hql = "from Inventory t where t.inventoryNO in (:inventoryNOs)";
		List<Inventory> list = this.getSession().createQuery(hql).setParameterList("inventoryNOs", inventoryNOs).list();
		return list;
	}
}
